package leetcode;

import java.util.HashMap;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/21 19:01
 */
public class Solution387_2 {
    public int firstUniqChar(String s) {

        int [] freq = new int[26];
        for (int i = 0; i < s.length(); i++) {
            freq[s.charAt(i)-'a'] ++;
        }

        for (int i = 0; i < s.length(); i++) {
            if(freq[s.charAt(i)-'a'] == 1){
                return i;
            }
        }
        return  -1;
    }


    public static void main(String[] args) {
        String s = "leetcode";
        int i = new Solution387_2().firstUniqChar(s);
        System.out.println(i);
    }


}
